#version 430 core

#define GRID_SIZE_X 64.f
#define GRID_SIZE_Y 64.f

layout(points) in;
layout(line_strip, max_vertices=2) out;

layout(binding=0) uniform sampler2D velocityTexture;

uniform mat4 viewProjMatrix;

void main(void)
{
	vec2 velocity = texelFetch(velocityTexture, ivec2(gl_in[0].gl_Position.xy * vec2(GRID_SIZE_X, GRID_SIZE_Y)), 0).xy;
	velocity *= 0.2;
	velocity = sign(velocity) * (1 - 1/(abs(velocity)+1));

	gl_Position = viewProjMatrix * gl_in[0].gl_Position;
	EmitVertex();

	gl_Position = viewProjMatrix * (gl_in[0].gl_Position + vec4(velocity * vec2(1.f/GRID_SIZE_X, 1.f/GRID_SIZE_Y), 0.f, 0.f));
	EmitVertex();

	EndPrimitive();
}